home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / SNIP9_91.ARJ / RM_ALL.C < prev    next >
C/C++ Source or Header  |  1991-09-10  |  1KB  |  56 lines

  1. /*
  2. **  remove all files
  3. **
  4. **  public domain demo by Bob Stout
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <io.h>
  11. #include <dos.h>
  12.  
  13. #define LAST_CHAR(str) (str[strlen(str) - 1])
  14.  
  15. #ifdef __TURBOC__
  16.  #define find_1st(n,a,b) (findfirst((n),(a),(b)))
  17.  #define find_nxt(b) (findnext(b))
  18.  #define ffblk ffblk
  19. #elif defined(__ZTC__)
  20.  #define find_1st(n,a,b) (NULL == ((b) = findfirst((n),(a))))
  21.  #define find_nxt(b) (NULL == ((b) = findnext()))
  22.  #define ffblk FIND
  23. #else   /* assume MSC/QC */
  24.  #define find_1st(n,a,b) (_dos_findfirst((n),(a),(b)))
  25.  #define find_nxt(b) (_dos_findnext(b))
  26.  #define ffblk find_t
  27. #endif
  28.  
  29. /* Select one of the following - remove() is ANSI       */
  30.  
  31. #define rmfunc remove
  32. /* #define rmfunc unlink */
  33.  
  34. main(int argc, char *argv[])
  35. {
  36.         char rmpath[67], *rmfile;
  37.         struct ffblk *fbuf
  38. #ifndef __ZTC__
  39.         = (struct ffblk *)malloc(sizeof(struct ffblk))
  40. #endif
  41.         ;
  42.  
  43.         if (2 > argc)
  44.                 strcpy(rmpath, ".\\");
  45.         else    strcpy(rmpath, argv[1]);
  46.         if ('\\' != LAST_CHAR(rmpath))
  47.                 strcat(rmpath, "\\");
  48.         rmfile = &rmpath[strlen(rmpath)];
  49.         strcpy(rmfile, "*.*");
  50.         if (0 == find_1st(rmpath, 0, fbuf)) do
  51.         {
  52.                 strcpy(rmfile, fbuf->name);
  53.                 rmfunc(rmpath);
  54.         } while (0 == find_nxt(fbuf));
  55. }
  56.